#ifndef _W25Q80_H_
#define _W25Q80_H_

#include "stm32f10x_gpio.h"
#include "delay.h"



extern unsigned char  Send_DATA[256];	 //??????
extern unsigned char  Recv_DATA[256];	 //??????, ?2??,??Recv_DATA[0] Recv_DATA[1]
extern unsigned char * Send_Pionter;
extern unsigned char * Recv_Pionter;

#define CS_Pin      GPIO_Pin_1
#define DO_Pin      GPIO_Pin_11
#define WP_Pin      GPIO_Pin_12
#define CLK_Pin     GPIO_Pin_14
#define HOLD_Pin    GPIO_Pin_15
#define DI_Pin      GPIO_Pin_13
#define CDW_GPIO    GPIOA      // cs do wp 
#define HDC_GPIO    GPIOC      // hold Di clk
 


#define CS_H()      (GPIO_SetBits(CDW_GPIO,CS_Pin))
#define CS_L()      (GPIO_ResetBits(CDW_GPIO,CS_Pin))

#define CLK_H()     (GPIO_SetBits(HDC_GPIO,CLK_Pin))
#define CLK_L()     (GPIO_ResetBits(HDC_GPIO,CLK_Pin))

#define DIO_H()     (GPIO_SetBits(HDC_GPIO,DI_Pin))
#define DIO_L()     (GPIO_ResetBits(HDC_GPIO,DI_Pin))

#define WP_H()     (GPIO_SetBits(CDW_GPIO,WP_Pin))
#define WP_L()     (GPIO_ResetBits(CDW_GPIO,WP_Pin))

#define HOLD_H()     (GPIO_SetBits(HDC_GPIO,HOLD_Pin))
#define HOLD_L()     (GPIO_ResetBits(HDC_GPIO,HOLD_Pin))

#define DIO_OUT()   (GPIO_Init(HDC_GPIO,DI_Pin,GPIO_Mode_Out_PP))
#define DIO_IN()    (GPIO_Init(HDC_GPIO,DI_Pin,GPIO_Mode_IN_FLOATING))

#define DO_READ()   (GPIO_ReadInputDataBit(CDW_GPIO,DO_Pin))

#define    uint8     unsigned char
#define    uint16    unsigned int
#define    uchar     unsigned char
#define    uint      unsigned int
#define    uint32    unsigned long

#define W25X_ReadStatus       0x05		//??????
#define W25X_WriteStatus      0x01		//??????
#define W25X_ReadDATA8        0x03		//??_??
#define W25X_FastRead         0x0B		//??_??
#define W25X_DualOutput       0x3B		//??_???
#define W25X_Write            0x02		//?_??_0~255???
#define W25X_S_Erase          0x20		//????4KB
#define	W25X_M_Erase	        0x52	        /* Erase 32KiB block */
#define W25X_B_Erase          0xD8		//????64KB
#define W25X_C_Erase          0xC7		//?????
#define W25X_PowerDown        0xB9		//??
#define W25X_PowerON_ID       0xAB		//?????ID
#define W25X_JEDEC_ID         0x9F		//????JEDEC_ID
#define W25X_WriteEnable      0x06		//???
#define W25X_WriteDisable     0x04		//???
#define W25X_BUSY             0x01		//FLASH?
#define W25X_NotBUSY          0x00		//FLASH?
#define W25Q80_LowPower       0xB9              //???
#define W25Q80 	              0XEF13 



void W25X16_INIT(void);
void WriteDisable (void); //???
void WriteEnable  (void); //???
unsigned char W25X_BUSY_OrNot (void); //???
void W25X_SectorErase(unsigned long Addre24);	//???????4KB??
void W25X_BlockErase(unsigned long Addre24);//????????,???????????
void W25X_Flash_Byte_Read (unsigned long Addre24,unsigned char Quantity);//????FLASH(1~256)  -W25X32-000000-3FFF00(4M)-
void W25X_Flash_Byte_Read1 (unsigned long Addre24,unsigned short Quantity);//????FLASH(1~256)  -W25X32-000000-3FFF00(4M)-
void W25X_Flash_Byte_Write(unsigned long Addre24,unsigned char Quantity); //?FLASH?????????(??256??)
void W25X_Flash_Byte_Write1(unsigned long Addre24,unsigned short Quantity);

unsigned char Read_OneByte(void);	  //?SPI?8??
void Send_OneByte(unsigned char DATA8);
void Delay100ms(unsigned int yy); //100ms???
void W25Q80IntoSleep(void);
void W25Q80WakeUp(void);
void W25Q80Check_ID(void);


#endif
